<?php

class Login implements SplSubject {

	protected $observers = [];

	public function __construct() {
		$this->observers = new SplObjectStorage();
	}

	public function login() {
		echo " I Login Now ";
		$this->notify();
	}

	public function attach(SplObserver $observer) {
		$this->observers->attach($observer);
	}

	public function detach(SplObserver $observer) {
		$this->observers->detach($observer);
	}

	public function notify() {
		$observers = $this->observers;

		$observers->rewind();

		while ($observers->valid()) {

			$observer = $observers->current();

			$observer->update($this);

			$observers->next();

		}
	}

}

class First implements SplObserver {
	public function update(SplSubject $subject) {
		echo 'I Know';
	}
}

$n = new Login();

$n->attach(new First());

$n->login();
